
package com.lzb.compressmaster.dialog;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.basic.BaseSmartDialog;
import com.lzb.compressmaster.databinding.DialogRenameBinding;
import com.lzb.compressmaster.databinding.DialogSetAnswerBinding;

public class SetAnswerDialog extends BaseSmartDialog<DialogSetAnswerBinding> implements View.OnClickListener {

    private String question, answer;

    public SetAnswerDialog(@NonNull Context context) {
        super(context);
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_set_answer;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        mDataBinding.etQuestion.setText(question);
        mDataBinding.etAnswer.setText(answer);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            String question = mDataBinding.etQuestion.getText().toString().trim();
            String answer = mDataBinding.etAnswer.getText().toString().trim();
            if (TextUtils.isEmpty(question)) {
                ToastUtils.showShort(R.string.please_input_password_question);
                return;
            }
            if (TextUtils.isEmpty(answer)) {
                ToastUtils.showShort(R.string.please_input_question_answer);
                return;
            }
            dismiss();
            if (listener != null) {
                listener.clickConfirm(question, answer);
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm(String question, String answer);
    }
}
